package com.xyht.sca_s.student_manage_system.modules.advanceRegistration.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.annotation.RequestPass;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.advanceRegistration.entity.req.*;
import com.xyht.sca_s.student_manage_system.modules.advanceRegistration.service.RxAdvanceRegistrationOrgService;
import com.xyht.sca_s.student_manage_system.modules.advanceRegistration.service.RxAdvanceRegistrationStudentInfoService;
import com.xyht.sca_s.student_manage_system.modules.chargePayment.entity.req.SmsWnsChargePaymentRecordReq;
import com.xyht.sca_s.student_manage_system.modules.dormitory.entity.req.SmsDormitoryInfoExportReq;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.concurrent.Future;

/**
 * <p>
 * 预报名学生信息 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-04-10
 */
@RestController
@RequestMapping("/advanceRegistration/studentInfo")
@SecretBody
public class RxAdvanceRegistrationStudentInfoController {

    @Resource
    private RxAdvanceRegistrationStudentInfoService advanceRegistrationStudentInfoService;

    @ApiOperation("添加学生信息")
    @PostMapping("/add")
    public ResponseResult addAdvanceRegistrationStudentInfo(@RequestBody RxAdvanceRegistrationStudentInfoReq addReq) {
        return advanceRegistrationStudentInfoService.addAdvanceRegistrationStudentInfo(addReq);
    }

    @ApiOperation("查看学生缴费信息")
    @GetMapping("/stuPaymentInfo")
    public ResponseResult getStuPaymentInfoList(@RequestParam(value = "searchStr", required = false) String searchStr,
                                                @RequestParam(value = "middleSchoolId", required = false) String middleSchoolId,
                                            @RequestParam(value = "orgId", required = false) String orgId,
                                            @RequestParam(value = "startDate", required = false) String startDate,
                                            @RequestParam(value = "endDate", required = false) String endDate,
                                            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        return advanceRegistrationStudentInfoService.getStuPaymentInfoList(pageNum,pageSize,searchStr,orgId,startDate,endDate,middleSchoolId);
    }

    @ApiOperation("学生缴费信息导出")
    @PostMapping("/paymentRecords/batch/export")
    public ResponseResult exportStuPaymentInfo(@RequestBody SmsAdvanceRegistrationPaymentRecordExportReq exportReq,
                                          HttpServletResponse response){
        ResponseResult responseResult;
        try{
            Future<ResponseResult> future = advanceRegistrationStudentInfoService.exportStuPaymentInfo(exportReq, response);
            while (true){
                if (future.isDone()){
                    break;
                }
            }
            responseResult = future.get();
        }catch (Exception e){
            e.printStackTrace();
            responseResult = CommonResult.failed(CommonCodeEnum.FAIL);
        }
        return responseResult;
    }

    @ApiOperation("微信授权")
    @PostMapping("/wxAuthorize")
    @RequestPass
    public ResponseResult wxAuthorize(@RequestBody WxCodeReq addReq) {
        return advanceRegistrationStudentInfoService.wxAuthorize(addReq);
    }

    @ApiOperation("查询该学生是否缴费")
    @GetMapping("/isPayment")
    @RequestPass
    public ResponseResult getStuIsPayment(@RequestParam("openId") String openId) {
        return advanceRegistrationStudentInfoService.getStuIsPayment(openId);
    }

    @ApiOperation("支付")
    @PostMapping("/payment")
    @RequestPass
    public ResponseResult payment(@RequestBody RxAdvanceRegistrationStudentPaymentReq req) {
        return advanceRegistrationStudentInfoService.payment(req);
    }


}

